<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv=X-UA-Compatible content="IE=edge,chrome=1">
    <meta content=always name=referrer>
    <link rel="stylesheet" href="__STATIC__/css_user/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="__STATIC__/css/newbase.css">
    <script src="__STATIC__/js/jquery-1.8.2.js"></script>
    <script src="__STATIC__/js/layer_mobile/layer.js"></script>
    <title>提现</title>
</head>
<body>
<div class="wrap-shop">
    <div class="header">
        <p>我要提现</p>
        <img src="__STATIC__/img/back.png" class="back"
             onclick=window.location.href="{:url('mobile/user_info/my_wallet')}">
        <span><a href="javascript:withdrawals();">确认提现</a></span>
    </div>
    <div class="center">
        <div class="main">
            <img src="__STATIC__/img_user/qiandao.png">
            <span class="cur">钱包余额(元)<br><span>{$balance}</span></span>
        </div>
        <div>
            <h4>提现金额</h4>
            <input type="text" placeholder="提现金额需大于1.00元" class="text" id="cash">
            <h4>银行名称</h4>
            <form role="form">
                <input type="text" placeholder="请输入银行名称" class="text" id="bank">
            </form>
            <h4>银行卡姓名</h4>
            <input type="text" placeholder="请输入银行卡号" class="text" id="real_name">
            <h4>银行账号</h4>
            <input type="text" placeholder="请输入银行卡号" class="text" id="card">
        </div>
    </div>
    <p class="tips">到账时间预计4-6天到账【请确认您填写信息的正确性】</p>
</div>
<script>
    function withdrawals() {
        var cash = $('#cash').val();
        var balance = parseFloat('{$balance}').toFixed(2);
        var bank = $('#bank').val();
        var card = $('#card').val();
        var real_name = $('#real_name').val();
        console.log(parseFloat(cash).toFixed(2) - balance);
        if (cash == '') {
            layer.open({content: '提现金额不能为空', skin: 'msg', time: 2});
            return false;
        } else if (cash < 1) {
            layer.open({content: '提现金额需大于1.00元', skin: 'msg', time: 2});
            return false;
        } else if (cash[0] == '-' || cash[0] == '0') {
            layer.open({content: '请输入正确的金额格式', skin: 'msg', time: 2});
            return false;
        } else if ((parseFloat(cash).toFixed(2) - balance) > 0) {
            layer.open({content: '余额不足', skin: 'msg', time: 2});
            return false;
        } else if (bank == '') {
            layer.open({content: '开户银行不能为空', skin: 'msg', time: 2});
            return false;
        } else if (card == '') {
            layer.open({content: '银行卡号不能为空', skin: 'msg', time: 2});
            return false;
        } else if (real_name == '') {
            layer.open({content: '银行卡姓名', skin: 'msg', time: 2});
            return false;
        }

        $.ajax({
            url: '',
            data: {'cash': cash, 'bank': bank, 'card': card,'real_name':real_name},
            type: 'post',
            dataType: 'json',
            success: function (data) {
                if (data.code == 200) {
                    layer.open({content: data.message, skin: 'msg', time: 2});

                    setTimeout(function () {
                        window.location.href = "{:url('mobile/user_info/my_shop_index')}";   //跳转到主页
                    },2000);

                } else {
                    layer.open({content: data.message, skin: 'msg', time: 2});
                }
            }

        })
    }
</script>
</body>
</html>